import { ErrorText } from "../../domain/enums/ErrorEnums";
import { ProductRepository } from "../../ports/repositories/ProductRepository";

/**
 * 商品应用服务 - 协调领域对象完成业务用例
 * 应用服务是领域层的外观，封装了领域逻辑的调用
 */
export class ProductApplicationService {
    // 依赖注入仓储接口，而不是具体实现
    constructor(private productRepository: ProductRepository) { }

    async getProductList() {
        return await this.productRepository.findAll();
    }

    async getProductInfo(id: number) {
        if (!id) {
            throw new Error(ErrorText.IdNotNull)
        }
        return await this.productRepository.findById(id);
    }
}